<?

require_once 'Zend/Db/Adapter/Abstract.php';
require_once 'Zend/Db/Select.php';

class Mojito_Db_Select_Mysql extends Zend_Db_Select
{

    const SQL_CALC_FOUND_ROWS = 'sqlCalcFoundRows';
    // add other options as needed

    public function __construct(Zend_Db_Adapter_Abstract $adapter)
    {
        /**
         * Use array_merge() instead of simply setting a key
         * because the order of keys is significant to the
         * rendering of the query.
         */
        self::$_partsInit = array_merge(
            array(
                self::SQL_CALC_FOUND_ROWS => false
                // add other options as needed
            ),
            self::$_partsInit
        );
        parent::__construct($adapter);
    }

    public function sqlCalcFoundRows($flag = true)
    {
        $this->_parts[self::SQL_CALC_FOUND_ROWS] = (bool) $flag;
        return $this;
    }

    protected function _renderSqlCalcFoundRows($sql)
    {
        if ($this->_parts[self::SQL_CALC_FOUND_ROWS]) {
            $sql .= ' SQL_CALC_FOUND_ROWS ';
        }

        return $sql;
    }

}